package com.gz.EuchreU.Contants;

import android.util.Log;


public class GameOptions {
	public static final int PREF_INT_GAME_SPEED = 0;
	public static final int PREF_INT_PAUSE_LENGTH = PREF_INT_GAME_SPEED + 1;
	public static final int PREF_BOOL_AUTO_PLAY_LAST = PREF_INT_PAUSE_LENGTH + 1;
	public static final int PREF_BOOL_AUTO_PLAY_31 = PREF_BOOL_AUTO_PLAY_LAST + 1;
	public static final int PREF_BOOL_SHOW_AI = PREF_BOOL_AUTO_PLAY_31 + 1;
	public static final int PREF_BOOL_LONER = PREF_BOOL_SHOW_AI + 1;
	public static final int PREF_BOOL_STD = PREF_BOOL_LONER + 1;
	public static final int PREF_BOOL_CALL_NO_TRUMP = PREF_BOOL_STD + 1;
	public static final int PREF_BOOL_FARMERS = PREF_BOOL_CALL_NO_TRUMP + 1;
	public static final int PREF_BOOL_DEALER_P_ORDER = PREF_BOOL_FARMERS + 1;
	public static final int PREF_INT_POINTS_TO_WIN = PREF_BOOL_DEALER_P_ORDER + 1;
	public static final int PREF_INT_P_SKILL = PREF_INT_POINTS_TO_WIN + 1;
	public static final int PREF_INT_O_LEFT_SKILL = PREF_INT_P_SKILL + 1;
	public static final int PREF_INT_O_RIGHT_SKILL = PREF_INT_O_LEFT_SKILL + 1;
	public static final int PREF_BOOL_LOW_RES = PREF_INT_O_RIGHT_SKILL + 1;
	public static final int PREF_BOOL_CALL_TURN = PREF_BOOL_LOW_RES + 1;
	public static final int PREF_BOOL_AI_ALWAYS_PASSES = PREF_BOOL_CALL_TURN + 1;
	
	//Options Menu
	private static int GameSpeed = 2;
	private static int PauseLength = 1;
	private static boolean AutoPlayLast = false;
	private static boolean AutoPlay31 = true;
	private static boolean ShowAICards = false;
	
	//Rules Menu
	private static boolean Loner = true;
	private static boolean StickTheDealer = true;
	private static boolean CallNoTrump = false;
	private static boolean FarmersHand = false;
	private static boolean DealersPCanOrderUp = true;
	private static int PointsToWin = 10;
	
	//Difficulty Menu
	private static int PartnerSkill = 3;
	private static int OppLeftSkill = 3;
	private static int OppRightSkill = 3;
	private static boolean AIPasses = false;
	
	private static boolean LowRes = false;
	private static boolean CallTurnSuit = false;
	
	public static int GetIntOption(int pPrefID){
		int intReturn = 0;
		
		switch(pPrefID){
		case PREF_INT_GAME_SPEED:
			intReturn = GameSpeed;
			break;
		case PREF_INT_PAUSE_LENGTH:
			intReturn = PauseLength;
			break;
		case PREF_INT_POINTS_TO_WIN:
			intReturn = PointsToWin;
			break;
		case PREF_INT_P_SKILL:		
			intReturn = PartnerSkill;
			break;
		case PREF_INT_O_LEFT_SKILL:
			intReturn = OppLeftSkill;
			break;
		case PREF_INT_O_RIGHT_SKILL:
			intReturn = OppRightSkill;
			break;
		default:
				log("Returning 5 as default - No ID found");
				intReturn = 5;
		}
		
		log("Getting Int Option: " + pPrefID + " " + GetPreferenceKey(pPrefID) + " = " + intReturn);
		return intReturn;
	}
	
	public static void SetIntOption(int pPrefID, int pValue){
		switch(pPrefID){
		case PREF_INT_GAME_SPEED:
			GameSpeed = pValue;
			break;
		case PREF_INT_PAUSE_LENGTH:
			PauseLength = pValue;
			break;
		case PREF_INT_POINTS_TO_WIN:
			PointsToWin = pValue;
			break;
		case PREF_INT_P_SKILL:		
			PartnerSkill = pValue;
			break;
		case PREF_INT_O_LEFT_SKILL:
			OppLeftSkill = pValue;
			break;
		case PREF_INT_O_RIGHT_SKILL:
			OppRightSkill = pValue;
			break;
		}
		
		UI.GetGame().SetIntPreference(GetPreferenceKey(pPrefID), pValue);
	}
	
	public static boolean GetBoolOption(int pPrefID){
		switch(pPrefID){
		case PREF_BOOL_AUTO_PLAY_LAST:
			return AutoPlayLast;
		case PREF_BOOL_AUTO_PLAY_31:
			return AutoPlay31;
		case PREF_BOOL_SHOW_AI:
			return ShowAICards;
		case PREF_BOOL_LONER:
			return Loner;
		case PREF_BOOL_STD:
			return StickTheDealer;
		case PREF_BOOL_CALL_NO_TRUMP:
			return CallNoTrump;
		case PREF_BOOL_FARMERS:
			return FarmersHand;
		case PREF_BOOL_DEALER_P_ORDER:
			return DealersPCanOrderUp;
		case PREF_BOOL_LOW_RES:
			return LowRes;
		case PREF_BOOL_CALL_TURN:
			return CallTurnSuit;
		case PREF_BOOL_AI_ALWAYS_PASSES:
			return AIPasses;
		default:
				return false;
		}
	}
	
	public static void SetBoolOption(int pPrefID, boolean pValue){
		switch(pPrefID){
		case PREF_BOOL_AUTO_PLAY_LAST:
			AutoPlayLast = pValue;
			break;
		case PREF_BOOL_AUTO_PLAY_31:
			AutoPlay31 = pValue;
			break;
		case PREF_BOOL_SHOW_AI:
			ShowAICards = pValue;
			break;
		case PREF_BOOL_LONER:
			Loner = pValue;
			break;
		case PREF_BOOL_STD:
			StickTheDealer = pValue;
			break;
		case PREF_BOOL_CALL_NO_TRUMP:
			CallNoTrump = pValue;
			break;
		case PREF_BOOL_FARMERS:
			FarmersHand = pValue;
			break;
		case PREF_BOOL_DEALER_P_ORDER:
			DealersPCanOrderUp = pValue;
			break;
		case PREF_BOOL_LOW_RES:
			LowRes = pValue;
			break;
		case PREF_BOOL_CALL_TURN:
			CallTurnSuit = pValue;
			break;
		case PREF_BOOL_AI_ALWAYS_PASSES:
			AIPasses = pValue;
		}
		
		UI.GetGame().SetBoolPreference(GetPreferenceKey(pPrefID), pValue);
	}
	
	private static String GetPreferenceKey(int pPrefID){
		switch(pPrefID){
		case PREF_INT_GAME_SPEED:
			return "game.speed";
		case PREF_INT_PAUSE_LENGTH:
			return "pause.length";
		case PREF_BOOL_AUTO_PLAY_LAST:
			return "auto.play.last";
		case PREF_BOOL_AUTO_PLAY_31:
			return "auto.play.done";
		case PREF_BOOL_SHOW_AI:
			return "show.ai";
		case PREF_BOOL_LONER:
			return "loner.hands";
		case PREF_BOOL_STD:
			return "stick.the.dealer";
		case PREF_BOOL_CALL_NO_TRUMP:
			return "call.no.trump";
		case PREF_BOOL_FARMERS:
			return "farmers.hand";
		case PREF_BOOL_DEALER_P_ORDER:
			return "dealer.p.can.order";
		case PREF_INT_POINTS_TO_WIN:
			return "points.to.win";
		case PREF_INT_P_SKILL:		
			return "p.skill";
		case PREF_INT_O_LEFT_SKILL:
			return "o.left.skill";
		case PREF_INT_O_RIGHT_SKILL:
			return "o.right.skill";
		case PREF_BOOL_LOW_RES:
			return "low.resolution";
		case PREF_BOOL_CALL_TURN:
			return "call.turn.suit";
		case PREF_BOOL_AI_ALWAYS_PASSES:
			return "ai.always.passes";
		default:
			return "no.pref";
		}
	}
	
	
/*	
	
	*/
	
	
	
	public static void GetDefaults(){
		log("Getting defaults");
		GameSpeed = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_GAME_SPEED) , GameSpeed);
		log("GameSpeed = " + GameSpeed);
		PauseLength = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_PAUSE_LENGTH), PauseLength);
		log("PauseLength = " + PauseLength);
		PointsToWin = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_POINTS_TO_WIN), PointsToWin);
		log("PointsToWin = " + PointsToWin);
		PartnerSkill = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_P_SKILL), PartnerSkill);
		log("PartnerSkill = " + PartnerSkill);
		OppLeftSkill = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_O_LEFT_SKILL), OppLeftSkill);
		log("OppLeftSkill = " + OppLeftSkill);
		OppRightSkill = UI.GetGame().GetIntPreference(GetPreferenceKey(PREF_INT_O_RIGHT_SKILL), OppRightSkill);
		log("OppRightSkill = " + OppRightSkill);
		
		AutoPlayLast = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_AUTO_PLAY_LAST), AutoPlayLast);
		AutoPlay31 = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_AUTO_PLAY_31), AutoPlay31);
		ShowAICards = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_SHOW_AI), ShowAICards);
		Loner = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_LONER), Loner);
		StickTheDealer = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_STD), StickTheDealer);
		//CallNoTrump = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_CALL_NO_TRUMP), CallNoTrump);
		//FarmersHand = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_FARMERS), FarmersHand);
		DealersPCanOrderUp = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_DEALER_P_ORDER), DealersPCanOrderUp);
		LowRes = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_LOW_RES), LowRes);
		//CallTurnSuit = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_CALL_TURN), CallTurnSuit);
		AIPasses = UI.GetGame().GetBoolPreference(GetPreferenceKey(PREF_BOOL_AI_ALWAYS_PASSES), AIPasses);
	}
	
	private static void log(String msg){
		Log.d("GameOptions", msg);
	}
}
